<?php
session_start();
$host = 'localhost';
$username = '';
$password = '';
$dbname = '';
$id = $_POST['id'];
$_SESSION['id'] = $id; //保存读者id,供borrowbook.php使用
$url1 = "Borrowbook.html";
$url2 = "homepage.html";
$mysql = new mysqli($host, $username, $password, $dbname);
if ($mysql->connect_errno) {
    die('数据库连接失败：' . $mysql->connect_errno);
} else {
    $mysql->set_charset('UTF-8'); //  设置数据库字符集
    $sql = "SELECT can from readerinfo where reader_id=$id";         // SQL 语句
    $result = $mysql->query($sql);
    $row = mysqli_fetch_row($result);
    if ($row[0] == 1) {
        $sql1 = "SELECT reader_name from readerinfo where reader_id=$id";
        $result1 = $mysql->query($sql1);
        $row1 = mysqli_fetch_row($result1);
        echo "<script>alert('欢迎您，$row1[0]')</script>";
        echo "<script language='javascript' type='text/javascript'>";
        echo "window.location.href='$url1'"; //跳转到借书页面
        echo "</script>";
        $mysql->close();
    } else {
        echo "<script>alert('抱歉，您暂时还没有资格借阅')</script>";
        echo "<script language='javascript' type='text/javascript'>";
        echo "window.location.href='$url2'"; //回到首页
        echo "</script>";
        $mysql->close();
    }
}
